import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
import "./index.css";
import { Provider } from "react-redux";
import { store } from "./utils/store/store";
import { ToastConfigProvider } from "./context/ToastContext";
import { toast, Toast } from "./components/Toast/Toast";
import { Login } from "./components/LoginAndRegister/Login/Login";
import { Register } from "./components/LoginAndRegister/Register/Register";
import { request } from "./utils/utils/request";
import { updateLogin } from "./utils/store/deviceSlice";
// import { FixedToast } from "./components/FixedToast/FixedToast";
request.interceptors.response.use((res) => {
  const code = res.data?.code;
  switch (code) {
    case 200:
      return res;
    case 2001:
      toast("error: " + res.data.msg);
      return Promise.reject(res);
    case 401:
      store.dispatch(updateLogin(true));
      return Promise.reject(res);
    case 500:
      toast("error: " + res.data.msg);
      return Promise.reject(res);
    default:
      return Promise.reject(res);
  }
});

ReactDOM.createRoot(document.getElementById("root")).render(
  <Provider store={store}>
    <ToastConfigProvider>
      <App />
      <Toast />
      {/* <FixedToast /> */}
      {/* <LoginAndRegister /> */}
      <Login />
      <Register />
    </ToastConfigProvider>
  </Provider>
);
